package com.example.tool.action.other;

import com.example.tool.ui.UpdateExeDialogWrapper;
import com.example.tool.utils.FileUtil;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

/**
 * <p>Title: PassWordActions</p >
 * Description: 更新辅助文件
 * <p>CreateTime: 2022/7/1 11:10</p>
 * @author FT
 */
public class UpdateExeActions extends AnAction {

  @Override
  public @NotNull ActionUpdateThread getActionUpdateThread() {
    return super.getActionUpdateThread();
  }

  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    UpdateExeDialogWrapper updateExeDialogWrapper = new UpdateExeDialogWrapper(project);
    if (updateExeDialogWrapper.showAndGet()) {
      try {
        String userExeFilePath = updateExeDialogWrapper.getUserPasswordExe().getText();
        String creatFormExeFilePath = updateExeDialogWrapper.getCreatFormExe().getText();
        String property = System.getProperty("user.home");
        if(!userExeFilePath.equals("")){
          FileUtil.copyFile(userExeFilePath, property + "/OA.exe");
        }
        if(!creatFormExeFilePath.equals("")){
          FileUtil.copyFile(creatFormExeFilePath, property + "/OAForm.exe");
        }
      } catch (IOException fileNotFoundException) {
        fileNotFoundException.printStackTrace();
      }
    }
  }
}
